//4位无符号乘法器
//a，b：输入，位宽为4，乘数
//p: 输出，位宽为8，乘积
module Mul4(a,b,p);
  input [3:0] a,b;
  output [7:0] p;
  //形成部分积
  wire [3:0] pp0 = a & {4{b[0]}};
  wire [3:0] pp1 = a & {4{b[1]}};
  wire [3:0] pp2 = a & {4{b[2]}};
  wire [3:0] pp3 = a & {4{b[3]}};
  //计算部分积之和
  wire cout1,cout2,cout3;
  wire [3:0] s1,s2,s3;
  Adder1 #(4) a1(pp1,{1'b0,pp0[3:1]},1'b0,cout1,s1);
  Adder2 #(4) a2(pp2,{cout1,s1[3:1]},1'b0,cout2,s2);
  Adder2 #(4) a3(pp3,{cout2,s2[3:1]},1'b0,cout3,s3);
  assign p={cout3,s3,s2[0],s1[0],pp0[0]};
endmodule

